﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Control_ShowBusTypeControl : System.Web.UI.UserControl
{
    private string check = null;
    private string gettype = null;
    private string getprice = null;
    ListAndProcessData wsv = new ListAndProcessData();
    protected void Page_Load(object sender, EventArgs e)
    {
        check = Request.QueryString["Loi"];
        //check = Convert.ToInt32(loi);
        gettype = Request.QueryString["typename"];
        getprice = Request.QueryString["price"];
        var a = wsv.getBusType();
        foreach (var item in a)
        {
            dropdownlist1.Items.Add(item.Name);
            dropdownlist2.Items.Add(item.Price.ToString());
        }
        
        try
        {
            if (check == "404")
            {
                lblnull.Visible = true;
                ListView1.DataSource = wsv.getBusType();
                ListView1.DataBind();
            }
            else
            {
                string type = gettype;
                string price = getprice;
                var content = wsv.searchBustype(type,price);
                if (content.Count != 0)
	            {
                    
                    ListView1.DataSource = content ;
                    ListView1.DataBind();
                }
                else
                {
                    Response.Redirect("showBusType_Admin.aspx?Loi=404");
                }  
                        

            }
        }
        catch (Exception)
        {
            ListView1.DataSource = wsv.getBusType();
            ListView1.DataBind();
              
        }
        
        
        
    }

    protected void btnsearch_Click1(object sender, EventArgs e)
    {
        if (check == "404")
        {
            Response.Redirect("showBusType_Admin.aspx?typename=" + dropdownlist1.SelectedItem.ToString() + "&&price=" + dropdownlist2.SelectedItem.ToString());
        }
        else
        {
            Response.Redirect("showBusType_Admin.aspx?typename=" + dropdownlist1.SelectedItem.ToString() + "&&price=" + dropdownlist2.SelectedItem.ToString());
        }
    }
}